using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using Marin.Entities;

namespace Marin.Repository.Mapping
{
    public class DetalleIngresoMap : EntityTypeConfiguration<DetalleIngreso>
    {
        public DetalleIngresoMap()
        {
            // Primary Key
            this.HasKey(t => new { t.Item, t.IdIngreso });

            this.Property(t => t.Item)
                 .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);


            this.Property(t => t.Motivo)
                .HasMaxLength(200);


            this.Property(d => d.Cantidad)
                      .HasPrecision(9, 2)
                      .IsRequired();

            this.Property(d => d.PrecioUnt)
                .HasPrecision(9, 2)
                .IsRequired();

            this.Ignore(d => d.Monto);

            // Table & Column Mappings
            this.ToTable("DetalleIngreso");
            this.Property(t => t.Item).HasColumnName("Item");
            
            this.Property(t => t.Motivo).HasColumnName("Motivo");
            this.Property(t => t.IdIngreso).HasColumnName("IdIngreso");
            this.Property(t => t.IdCuenta).HasColumnName("IdCuenta");
            this.Property(d => d.Cantidad).HasColumnName("Cantidad");
            this.Property(d => d.PrecioUnt).HasColumnName("PrecioUnt");

            // Relationships
            this.HasRequired(t => t.Cuenta)
                .WithMany()
                .HasForeignKey(d => d.IdCuenta);


            this.HasRequired(t => t.Ingreso)
                .WithMany(t => t.DetalleIngresoes)
                .HasForeignKey(d => d.IdIngreso);

        }
    }
}
